package com.hpf.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @datetime: 2020/10/31 15:02
 * @author: huangpengfei
 */
@RestController
@Slf4j
public class FlowLimitController {

    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }

    @GetMapping("/bye")
    public String bye(){
        System.out.println(Thread.currentThread().getName()+ "\t bye");
        return "byebye";
    }

    @GetMapping("/hotKey")
    @SentinelResource(value = "hotKey",blockHandler = "dealHotKey")
    public String testHotKey(@RequestParam(value = "p1",required = false)String p1,@RequestParam(value = "p2",required = false)String p2){
        return p1 + "----" +p2;
    }

    public String dealHotKey(String p1, String p2, BlockException exception){
        return "dealHotKey";
    }
}
